package com.ly.web.controller.king;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.kingdee.bos.webapi.entity.IdentifyInfo;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.exception.CustomException;
import com.ly.common.utils.erp.KingConstUtil;
import com.ly.heart.domain.KingOrgEntity;
import com.ly.heart.service.IKingOrgService;
import com.ly.heart.service.king.base.BusinessGroupPushService;
import com.ly.heart.util.CurrentUserUtil;
import com.ly.heart.util.KingCommonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api ( value = "BusinessGroupRemote", tags = "推基础数据-业务组" )
@RestController
@RequestMapping ( "/heart/BusinessGroupRemote" )
@Slf4j
public class BusinessGroupRemote {

    @Resource
    private IKingOrgService iKingOrgService;
    @Resource
    private BusinessGroupPushService businessGroupPushService;

    @ApiOperation ( "同步拉取金蝶银行账号" )
    @RequestMapping ( "pull" )
    public AjaxResult queryList () {
        KingOrgEntity orgEntity = iKingOrgService.getOne ( new LambdaQueryWrapper<KingOrgEntity> ().eq ( KingOrgEntity :: getOrgId, CurrentUserUtil.getCompanyId () ).eq ( KingOrgEntity :: getIsDisabled, false ) );
        if ( orgEntity == null ) {
            throw new CustomException ( "请先至系统管理中配置金蝶账套！" );
        }
        IdentifyInfo identifyInfo = KingCommonUtil.getIdentifyInfo ( orgEntity );
        K3CloudApi client = new K3CloudApi ( identifyInfo );
        //请求参数，要求为json字符串
        String jsonData = "{\"FormId\":\"" + KingConstUtil.CN_BANKACNT + "\",\"FieldKeys\":\"FNumber,FName,FACCOUNTTYPE,FBANKID,FIsFundUp,FUpType,FUpAmount,FBaseAmount,FMinUpAmount,FInOrOut,FIsSupBank,FISDEFAULTBANK,FIsAutoBlend,FIsSupAutoDER,FIsSupAutoDERT,FIsSupDZHD\",\"FilterString\":[],\"OrderString\":\"\",\"TopRowCount\":0,\"StartRow\":0,\"Limit\":2000,\"SubSystemId\":\"\"}";

        return AjaxResult.success ("业务组同步成功");
    }

}
